﻿using System;
using System.Linq;
using HtmlAgilityPack;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace Mvc.RazorTools.Glyphicons.Tests
{
	[TestClass]
	public class GlyphiconExtensionsTests
	{
		[TestMethod]
		[TestCategory("GlyphiconExtensionsTests")]
		public void CustomizeTest()
		{
			Glyphicon icon = GlyphiconsSet.Free.Star.Customize(new string[] { "value1", "value2", "value3" });

			HtmlNode node = icon.HtmlNode();
			Assert.AreEqual(true, node.Attributes.Contains("class"));
			Assert.AreEqual(true, node.Attributes["class"].Value.Contains(icon.IconId));
			Assert.AreEqual(true, node.Attributes["class"].Value.Contains("value1"));
			Assert.AreEqual(true, node.Attributes["class"].Value.Contains("value2"));
			Assert.AreEqual(true, node.Attributes["class"].Value.Contains("value3"));
		}

		[TestMethod]
		[TestCategory("GlyphiconExtensionsTests")]
		[ExpectedException(typeof(ArgumentNullException))]
		public void CustomizeNullIconParamTest()
		{
			Glyphicon icon1 = null;
			Glyphicon icon2 = icon1.Customize();
		}

		[TestMethod]
		[TestCategory("GlyphiconExtensionsTests")]
		[ExpectedException(typeof(ArgumentNullException))]
		public void CustomizeNullItemsParamTest()
		{
			Glyphicon icon2 = GlyphiconsSet.Free.Star.Customize(null);
		}

		[TestMethod]
		[TestCategory("GlyphiconExtensionsTests")]
		public void LargeTest()
		{
			Glyphicon icon = GlyphiconsSet.Free.Star.Large();
			HtmlNode node = icon.HtmlNode();
			Assert.AreEqual(true, node.Attributes.Contains("class"));
			Assert.AreEqual(true, node.Attributes["class"].Value.Contains(icon.IconId));
			Assert.AreEqual(true, node.Attributes["class"].Value.Contains(GlyphiconsSet.Free.Star.Large().CssOnly()));
		}

		[TestMethod]
		[TestCategory("GlyphiconExtensionsTests")]
		[ExpectedException(typeof(ArgumentNullException))]
		public void LargeNullIconParamTest()
		{
			Glyphicon icon1 = null;
			Glyphicon icon2 = icon1.Large();
		}

		[TestMethod]
		[TestCategory("GlyphiconExtensionsTests")]
		public void WhiteTest()
		{
			Glyphicon icon = GlyphiconsSet.Free.Star.White();
			
			HtmlNode node = icon.HtmlNode();
			Assert.AreEqual(true, node.Attributes.Contains("class"));
			Assert.AreEqual(true, node.Attributes["class"].Value.Contains(icon.IconId));
			Assert.AreEqual(true, node.Attributes["class"].Value.Contains(GlyphiconsSet.Free.Star.White().CssOnly()));
		}

		[TestMethod]
		[TestCategory("GlyphiconExtensionsTests")]
		[ExpectedException(typeof(ArgumentNullException))]
		public void WhiteNullIconParamTest()
		{
			Glyphicon icon1 = null;
			Glyphicon icon2 = icon1.White();
		}

		[TestMethod]
		[TestCategory("GlyphiconExtensionsTests")]
		public void CssOnlyTest1()
		{
			string css = GlyphiconsSet.Free.Check.CssOnly();
			string[] items = css.Split(new char[] { ' ' });
			Assert.AreEqual(true, items.Contains(GlyphiconsSet.Free.Check.IconId));
		}

		[TestMethod]
		[TestCategory("GlyphiconExtensionsTests")]
		public void CssOnlyTest2()
		{
			string css = GlyphiconsSet.Free.Check.Customize("style1").CssOnly();
			string[] items = css.Split(new char[] { ' ' });
			Assert.AreEqual(true, items.Contains(GlyphiconsSet.Free.Check.IconId));
			Assert.AreEqual(true, items.Contains("style1"));
		}
	}
}
